package com.atguigu.userprofile.util

import java.io.InputStreamReader
import java.util.Properties

/**
 * 获取resource下配置文件中的配置项
 */
object MyPropertiesUtil {


  def main(args: Array[String]): Unit = {
    val properties: Properties = MyPropertiesUtil.load("config.properties")
    println(properties.getProperty("user-profile.dbname"))
  }

  /**
   * 传入一个配置文件的名称,返回一个配置类对象 Properties. ==> 通过这个配置对象可以获取具体的属性值.
   * @param propertiesName
   * @return Properties
   */
  def load(propertiesName: String): Properties = {
    val prop = new Properties();
    prop.load(new InputStreamReader(Thread.currentThread().getContextClassLoader.
      getResourceAsStream(propertiesName), "UTF-8"))
    prop
  }

}

